package com.wswy.wzcx.ui.njdb

import android.os.Bundle
import android.text.format.DateFormat
import com.wswy.wzcx.R
import com.wswy.wzcx.api.ConfigsKt
import com.wswy.wzcx.model.DataCenter
import com.wswy.wzcx.model.PaymentOrder
import com.wswy.wzcx.model.license.UserCarInfo
import com.wswy.wzcx.module.base.CBaseFragment
import com.wswy.wzcx.module.base.getColor
import com.wswy.wzcx.module.base.onClick
import com.wswy.wzcx.module.pay.PayManager
import com.wswy.wzcx.ui.Constants
import com.wswy.wzcx.ui.activity.ModuleActivity
import com.wswy.wzcx.ui.web.WebViewActivity
import kotlinx.android.synthetic.main.fragment_njdb_pay_success.*
import java.util.*


/**
 * 代办步骤成功
 */
class NjdbStepFragment : CBaseFragment() {

    companion object{
        const val TAG = "_NjdbStepFragment"

        const val EXTRA_STEP = "_extra.step"

        /**
         * 上传成功
         */
        const val STEP_UPLOAD_SUCCESS = 1
        /**
         * 支付成功
         */
        const val STEP_PAY_SUCCESS = 2

        /**
         * 年检处理
         */
        const val STEP_NJ_PROCESS = 3
        /**
         * 回寄标志
         */
        const val STEP_SEND_NJ = 4

        @JvmStatic
        fun newInstance(bundle: Bundle):NjdbStepFragment{
            return NjdbStepFragment().apply {
                arguments = bundle
            }
        }

    }

    override fun getContentLayoutId(): Int {
        return R.layout.fragment_njdb_pay_success
    }

    override fun getFragmentTitle(): String {
        return "支付成功"
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        arguments?.getParcelable<PaymentOrder?>("extra.order")?.let {
            tv_step_money.text = getString(R.string.amount_args,it.amount)
            tv_pay_info.text = getString(R.string.order_payment_tips,PayManager.getPayStyleMode(it.payStyle,PayManager.PAY_TYPE_NORMAL)?.title,DateFormat.format("MM-dd HH:mm", Date()))

            postStep(STEP_PAY_SUCCESS)

        }

        //查看订单
        tv_submit.onClick {

            WebViewActivity.startWebview(context, ConfigsKt.H5_ORDER_LIST().format(0, DataCenter.get().userMode?.token))
            finish()
        }

        tv_go_home.onClick {
            finish()
        }


    }

    private fun postStep(step:Int){

        when(step){

            STEP_UPLOAD_SUCCESS -> {
                img_step_1.setImageResource(R.drawable.order_paysucessed)
                tv_step_title1.setTextColor(getColor(R.color.colorPrimary))
                view_line_1.setBackgroundColor(getColor(R.color.color_line))
            }

            STEP_PAY_SUCCESS -> {
                img_step_1.setImageResource(R.drawable.order_paysucessed)
                tv_step_title1.setTextColor(getColor(R.color.textColorPrimary))

                img_step_2.setImageResource(R.drawable.order_paysucessed)
                tv_step_title2.setTextColor(getColor(R.color.colorPrimary))

                view_line_1.setBackgroundColor(getColor(R.color.colorPrimary))
            }

            STEP_NJ_PROCESS -> {

                img_step_1.setImageResource(R.drawable.order_paysucessed)
                tv_step_title1.setTextColor(getColor(R.color.textColorPrimary))

                img_step_2.setImageResource(R.drawable.order_paysucessed)
                tv_step_title2.setTextColor(getColor(R.color.textColorPrimary))

                img_step_3.setImageResource(R.drawable.order_paysucessed)
                tv_step_title3.setTextColor(getColor(R.color.colorPrimary))

                view_line_1.setBackgroundColor(getColor(R.color.colorPrimary))
                view_line_2.setBackgroundColor(getColor(R.color.colorPrimary))

            }


            STEP_SEND_NJ -> {


                img_step_1.setImageResource(R.drawable.order_paysucessed)
                tv_step_title1.setTextColor(getColor(R.color.textColorPrimary))

                img_step_2.setImageResource(R.drawable.order_paysucessed)
                tv_step_title2.setTextColor(getColor(R.color.textColorPrimary))

                img_step_3.setImageResource(R.drawable.order_paysucessed)
                tv_step_title3.setTextColor(getColor(R.color.textColorPrimary))

                img_step_4.setImageResource(R.drawable.order_paysucessed)
                tv_step_title4.setTextColor(getColor(R.color.colorPrimary))

                view_line_1.setBackgroundColor(getColor(R.color.colorPrimary))
                view_line_2.setBackgroundColor(getColor(R.color.colorPrimary))
                view_line_3.setBackgroundColor(getColor(R.color.colorPrimary))
            }
        }

    }

}